<?php 
	/* favourites number table script */
	
	//start the session
	session_start();
	
	//checks if user has logged in and if not displays an error message
	if(!isset($_SESSION['username']))
	{
		$_SESSION['message'] = "<span style='color: red; font-weight: bold;'>You are not logged in to view this page.</span>";
		header('Location: Login.php');
	}
	
	//retrieves the file into an array where each line is a value
	$bookmarks_file = './bookmarks_data/bookmark_number_database.txt';
	$favourites = file($bookmarks_file);
	
	//counts the size of the $favourites array and loops through outputting data
	//into the array until it is complete
	for($i = 0; $i < count($favourites); $i++)
	{	
		//reads the array line for line
		$temp = explode(" | ", $favourites[$i]);
		$favourites[$i] = array('category' => $temp[0], 'number' => $temp[1]);
	}
?>

<!-- favourites_number_table.php view -->

<html>
	<head>
		<title>Favourite Count Table</title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	
	<body>
		<div id="wrapper">
			<div id="banner"><img src="images/bannerv0.jpg" alt="header graphic"></div>
			<div id="wrapper_links"><?php include("menu/menu.php");?></div>
			<div id="wrapper_body">

				<p align="left">User: <?php echo $_SESSION['username'];?></p>

				<h3>Favourites Count</h3>
   						
				<center>
					<table border="1" bgcolor="#202020">
						<tr>
							<th>Category</th>
							<th>Number of Favourites</th>
						</tr>
						
						
						<?php 
							//creates a foreach loop that cycles through the $favourite array 
							//outputting its variables into a table
							foreach($favourites as $favourite):
						?>
						
						<tr>
							<td><?php echo $favourite['category']?></td>
							<td><?php echo $favourite['number'];?></td>
						</tr>
						
						<?php endforeach;?>
						
					</table>
				</center>
			</div>
		</div>
	</body>
</html>